<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layui/css/layui.css">
    <script src="../js/jquery.min.js"></script>
</head>
<body>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>选取导师</legend>
</fieldset>

<table class="layui-hide" id="test" lay-filter="test"></table>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
        <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
    </div>

</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn " lay-event="edit">选中</a>
</script>


<script src="../layui/layui.js" charset="utf-8"></script>


<script >


    layui.use('table', function(){
        var table = layui.table;

        table.render({
            elem: '#test'
            ,url:'/teacher/chaXunAll'
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['filter', 'exports', 'print']
            ,title: '用户数据表'
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'tno', title:'教师工号', width:150, fixed: 'left', unresize: true, sort: true}
                ,{field:'tname', title:'教师名称', width:250, edit: 'text'}
                ,{field:'snumber', title:'剩余个数', width:250, edit: 'text'}
                ,{fixed:'right', title:'操作', toolbar: '#barDemo'}
            ]]
            ,page: true
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选');
                    break;

                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
                case 'add':
                    layer.open({
                        type: 2,
                        title: '添加界面',
                        area: ['350px', '350px'],
                        content:'addTeacher.html'

                    });

            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'edit'){
                    $.ajax({
                        url: "/ts/xinZeng",
                        contentType: "application/json",
                        method:"post",
                        data:JSON.stringify({
                            sno:201817025,
                            tno:data.tno,
                        }),
                        success:function (res) {
                            if(res.code==200){
                                layer.msg("选中成功");

                            }else {
                                layui.use('layer', function(){
                                    var layer = layui.layer;

                                    layer.msg('选中失败');
                                });
                            }
                            layer.close();
                        }
                    });
            } else {
                layer.open({
                    type: 1,
                    title:'警告界面',
                    content:"选取出错，请稍后再选！！"

                });
            }
        });
    });



</script>

</body>
</html>